package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.CallOrderUseRecord;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.CallOrderUseRecordMapper;
import com.zrwl.poscloud.xo.service.CallOrderUseRecordService;
import com.zrwl.poscloud.xo.vo.CallOrderUseRecordVO;

import javax.annotation.Resource;

/**
 * 通话订单使用记录 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-06-09
 */
@Service
public class CallOrderUseRecordServiceImpl extends SuperServiceImpl<CallOrderUseRecordMapper,CallOrderUseRecord> implements CallOrderUseRecordService {

    @Autowired
    private CallOrderUseRecordService callOrderUseRecordService;
    @Resource
    private CallOrderUseRecordMapper callOrderUseRecordMapper;
    @Override
    public IPage<CallOrderUseRecordVO> getPageList(CallOrderUseRecordVO callOrderUseRecordVO){
       Page<CallOrderUseRecord> page = new Page<>();
       page.setCurrent(callOrderUseRecordVO.getCurrentPage());
       page.setSize(callOrderUseRecordVO.getPageSize());
       IPage<CallOrderUseRecordVO> pageList = callOrderUseRecordMapper.getPageList(page, callOrderUseRecordVO);
       List<CallOrderUseRecordVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<CallOrderUseRecord> getAllList(CallOrderUseRecordVO callOrderUseRecordVO){
        QueryWrapper<CallOrderUseRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<CallOrderUseRecord> list = callOrderUseRecordService.list(queryWrapper);
        return list;
}
    @Override
    public String add(CallOrderUseRecordVO callOrderUseRecordVO){
        CallOrderUseRecord entity = new CallOrderUseRecord();
        BeanUtils.copyProperties(callOrderUseRecordVO, entity, SysConf.STATUS);
        entity.insert();
        callOrderUseRecordVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(CallOrderUseRecordVO callOrderUseRecordVO){
        CallOrderUseRecord entity = callOrderUseRecordService.getById(callOrderUseRecordVO.getUid());
        BeanUtils.copyProperties(callOrderUseRecordVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(CallOrderUseRecordVO callOrderUseRecordVO){
        CallOrderUseRecord entity = callOrderUseRecordService.getById(callOrderUseRecordVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
